function [herf] = herfindahl(id,year,w)

[h1,h2,ii]=unique(id);
[h1,h2,jj]=unique(year);

N=max(ii);
T=max(jj);

bigw=zeros(N,T);
bigw(sub2ind([N T],ii,jj))=w.*w;

herf = sum(bigw,1)